package com.itwjr.jdbc2.Test1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver") ;

        //获取连接
        String url = "jdbc:mysql://127.0.0.1:3306/db1";

        String user = "root";
        String psw = "1234";
        Connection connection = DriverManager.getConnection(url, user, psw);

        //定义sql语句
        //String sql = "update user set age = 199 where id = 1 ";
        //String sql = "insert  into  user values (null ,'张麻子',55)";
        String sql = "delete from user where id = 5";
        //获取statement对象,包装sql语句
        Statement statement = connection.createStatement();

        //执行update语句  返回结果
        int i = statement.executeUpdate(sql);

        //关闭资源
        statement.close();
        connection.close();


    }
}